/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.area_info_rate.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.area_info_rate.entity.TAreaInfoRate;
import com.thinkgem.jeesite.modules.area_info_rate.service.TAreaInfoRateService;

/**
 * 车位使用情况Controller
 * @author admin
 * @version 2019-04-10
 */
@Controller
@RequestMapping(value = "${adminPath}/area_info_rate/tAreaInfoRate")
public class TAreaInfoRateController extends BaseController {

	@Autowired
	private TAreaInfoRateService tAreaInfoRateService;
	
	@ModelAttribute
	public TAreaInfoRate get(@RequestParam(required=false) String id) {
		TAreaInfoRate entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tAreaInfoRateService.get(id);
		}
		if (entity == null){
			entity = new TAreaInfoRate();
		}
		return entity;
	}
	
	@RequiresPermissions("area_info_rate:tAreaInfoRate:view")
	@RequestMapping(value = {"list", ""})
	public String list(TAreaInfoRate tAreaInfoRate, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TAreaInfoRate> page = tAreaInfoRateService.findPage(new Page<TAreaInfoRate>(request, response), tAreaInfoRate); 
		model.addAttribute("page", page);
		return "modules/area_info_rate/tAreaInfoRateList";
	}

	@RequiresPermissions("area_info_rate:tAreaInfoRate:view")
	@RequestMapping(value = "form")
	public String form(TAreaInfoRate tAreaInfoRate, Model model) {
		model.addAttribute("tAreaInfoRate", tAreaInfoRate);
		return "modules/area_info_rate/tAreaInfoRateForm";
	}

	@RequiresPermissions("area_info_rate:tAreaInfoRate:edit")
	@RequestMapping(value = "save")
	public String save(TAreaInfoRate tAreaInfoRate, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tAreaInfoRate)){
			return form(tAreaInfoRate, model);
		}
		tAreaInfoRateService.save(tAreaInfoRate);
		addMessage(redirectAttributes, "保存车位使用情况成功");
		return "redirect:"+Global.getAdminPath()+"/area_info_rate/tAreaInfoRate/?repage";
	}
	
	@RequiresPermissions("area_info_rate:tAreaInfoRate:edit")
	@RequestMapping(value = "delete")
	public String delete(TAreaInfoRate tAreaInfoRate, RedirectAttributes redirectAttributes) {
		tAreaInfoRateService.delete(tAreaInfoRate);
		addMessage(redirectAttributes, "删除车位使用情况成功");
		return "redirect:"+Global.getAdminPath()+"/area_info_rate/tAreaInfoRate/?repage";
	}

}